#!/bin/bash

# postinst script for driver-storage-mega-sas
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:bin $BASEDIR/usr/share/man/man4d
	chown root:bin $BASEDIR/usr/share/man
	chown root:sys $BASEDIR/kernel
	chown root:sys $BASEDIR/kernel/drv
	chown root:sys $BASEDIR/kernel/drv/amd64
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/mega_sas.conf ] && rm -f $BASEDIR/kernel/drv/mega_sas.conf
	else
	    chmod 0644 "$BASEDIR/kernel/drv/mega_sas.conf"
	    chown root:sys "$BASEDIR/kernel/drv/mega_sas.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/mega_sas ] && rm -f $BASEDIR/kernel/drv/amd64/mega_sas
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/mega_sas"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/mega_sas"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^mega_sas " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -c 'scsi' -i '"pci1000,57.8086.3002" "pci1000,60.1000.1006" "pci1000,60.1000.100a" "pci1000,60.1000.100e" "pci1000,60.1000.100f" "pci1000,60.1000.1010" "pci1000,60.1000.1011" "pci1000,60.1000.1012" "pci1000,60.1000.1013" "pci1000,60.1000.1014" "pci1000,60.1000.1015" "pci1000,60.1000.1016" "pci1000,60.1000.1017" "pci1000,60.1000.1018" "pci1000,60.1000.1019" "pci1000,60.1000.101a" "pci1000,60.1000.101b" "pci1000,60.1000.1021" "pci1000,60.1000.1022" "pci1000,60.1014.363" "pci1000,60.1014.364" "pci1000,60.1014.365" "pci1000,60.1014.379" "pci1000,60.1014.3a2" "pci1000,60.1014.3ac" "pci1000,60.1028.1f0a" "pci1000,60.1028.1f0b" "pci1000,60.1028.1f0c" "pci1000,60.1028.1f0d" "pci1000,60.1028.1f11" "pci1000,60.1033.835a" "pci1000,60.1033.836e" "pci1000,60.1043.824d" "pci1000,60.1054.3019" "pci1000,60.1170.2f" "pci1000,60.1170.34" "pci1000,60.1170.36" "pci1000,60.1458.1000" "pci1000,60.15d9.c080" "pci1000,60.1734.10f9" "pci1000,60.1734.1102" "pci1000,60.1734.114b" "pci1000,60.17aa.6b7c" "pci1000,60.18a1.3" "pci1000,60.19e5.2001" "pci1000,60.19e5.2002" "pci1000,60.19e5.2003" "pci1000,60.19e5.2004" "pci1000,60.19e5.2005" "pci1000,60.19e5.2006" "pci1000,60.19e5.2010" "pci1000,60.19e5.2011" "pci1000,60.19e5.2012" "pci1000,60.19e5.2013" "pci1000,60.19e5.2014" "pci1000,60.19e5.2015" "pci1000,60.19e5.2016" "pci1000,60.19e5.2017" "pci1000,60.19e5.2018" "pci1000,60.19e5.2019" "pci1000,60.19e5.201a" "pci1000,60.19e5.d203" "pci1000,60.1b0a.14" "pci1000,60.1fca.2163" "pci1000,60.1fca.2164" "pci1000,60.8086.1006" "pci1000,60.8086.100a" "pci1000,60.8086.1010" "pci1000,60.8086.1013" "pci1000,60.8086.1021" "pci1000,60.8086.34cc" "pci1000,60.8086.34cd" "pci1000,60.8086.34e4" "pci1000,60.8086.3505" "pci1000,60.8086.3508" "pci1000,7c.1000.101c" "pci1000,7c.1000.101d" "pci1000,7c.1014.395" "pci1000,411.1000.1001" "pci1000,411.1000.1002" "pci1000,411.1000.1003" "pci1000,411.1000.1004" "pci1000,411.1000.1008" "pci1000,411.1000.100c" "pci1000,411.1000.100d" "pci1000,411.1000.2004" "pci1000,411.1000.2005" "pci1000,411.1033.8287" "pci1000,411.1054.3016" "pci1000,411.1734.1081" "pci1000,411.1734.10a3" "pci1000,411.8086.1001" "pci1000,411.8086.1003" "pci1000,411.8086.1008" "pci1000,411.8086.3490" "pci1000,411.8086.3500" "pci1000,411.8086.3501" "pci1000,411.8086.3504" "pci1000,411.8086.3507" "pci1000,413.1000.1005" "pci1028,15.1028.1f01" "pci1028,15.1028.1f02" "pci1028,15.1028.1f03"' mega_sas ) )
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

